﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SchoolManagementSystem.Controls;
using CoreData;
using Helper;
namespace SchoolManagementSystem.Details
{
    public partial class Receipt_Payment_ReasonUC : DetailUC
    {
        public int type;
        public Receipt_Payment_ReasonUC(int type)
        {
            InitializeComponent();
            this.type = type;
            if (type == 1)
            {
                this.ObjectName = "Lý do thu";
                this.Code = "ReceiptReason";
            }
            if (type == 2)
            {
                this.ObjectName = "Lý do chi";
                this.Code = "PaymentReason";
            }
            this.Type = new Payment_Reason();
        }


        protected override long DetailDisplay()
        {
            Payment_Reason data = new Payment_Reason();
            if (ID > 0)
            {
                data = (Payment_Reason)RegisterService.RegisterServices.PaymentReasonService.GetByID(ID);
            }

            txtname.Text = data.Name;
            txtnote.Text = data.Description;
            txtcode.Text = data.Code;
            ckactive.Checked = data.Active;

            return ID;

        }

        protected override long Save()
        {
            Payment_Reason data = new Payment_Reason();
            if (ID > 0)
            {
                data = (Payment_Reason)RegisterService.RegisterServices.PaymentReasonService.GetByID(ID);

            }
            data.Code = txtcode.Text;
            data.Name = txtname.Text;
            data.Description = txtnote.Text;
            data.Active = ckactive.Checked;
            data.Type = type;

            ID = RegisterService.RegisterServices.PaymentReasonService.Save(data);

            return ID;
        }


        public override bool Delete(long SelectedID)
        {

            return RegisterService.RegisterServices.PaymentReasonService.Delete(RegisterService.RegisterServices.PaymentReasonService.GetByID(SelectedID));

        }

        private void Receipt_Payment_ReasonUC_Load(object sender, EventArgs e)
        {
            AddTextChanged(groupControl1.Controls);
        }
    }
}
